from typing import Optional

from kubernetes_asyncio import client

from balder.services.kube_base import KubeBase, format_selector


class PobService(KubeBase):
    async def get_pob_list(self, namespace: str, label_selector: Optional[dict] = None, field_selector: Optional[dict] = None) -> client.V1PodList:
        pod_label_selector, pod_field_selector = format_selector(label_selector, field_selector)

        return await self.core_v1_api.list_namespaced_pod(namespace=namespace, label_selector=pod_label_selector, field_selector=pod_field_selector)

    async def get_pob(self, namespace: str, name: str) -> client.V1Pod:
        return await self.core_v1_api.read_namespaced_pod(namespace=namespace, name=name)

    async def get_pod_log(self, namespace: str, name: str) -> str:
        return await self.core_v1_api.read_namespaced_pod_log(namespace=namespace, name=name)
